home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / foundation / NSArchiver.h next >
Text File  |  1994-09-02  |  4KB  |  132 lines

  1. /*      NSArchiver.h
  2.     Serializing objects
  3.     Copyright 1994, NeXT Computer Inc.
  4. */
  5.  
  6. #import <foundation/NSCoder.h>
  7. #import <foundation/NSData.h>
  8. #import <foundation/NSDictionary.h>
  9. #import <objc/hashtable.h>
  10.  
  11. /************        Archiving: Writing    ****************/
  12.  
  13. @interface NSArchiver:NSCoder {
  14.     @private
  15.     NSMutableData    *mdata;
  16.     void        *pointerTable; // pointer -> num
  17.     void        *stringTable; // string -> num
  18.     BOOL        noteConditionals; /* when YES, a no-write pass */
  19.     NXHashTable        *ids;    /* Set of all visited IDs */
  20. }
  21.  
  22. - initForWritingWithMutableData:(NSMutableData *)mdata;
  23.     /* mdata is retained */
  24.     
  25. - (NSMutableData *)archiverData;
  26.  
  27. - (void)encodeRootObject:rootObject;
  28.     /* Specifies that a data structure might contain backpointers, and writes it as with -encodeObject:.  This method cannot be called recursively.  The implementation works in 2 passes, which implies that write: methods will be performed twice. */
  29.  
  30. - (void)encodeConditionalObject:object;
  31.     /* Indicates that object is a back pointer, and writes it as with -encodeObject: or writes nil depending on whether object is written by an unconditional -encodeObject: otherwise.  Implies a previous call to -encodeRootObject:. */
  32.  
  33. - (void)encodeArrayOfObjCType:(const char *)type count:(unsigned)count at:(const void *)array;
  34.  
  35. + (NSData *)archivedDataWithRootObject:rootObject;
  36.  
  37. + (BOOL)archiveRootObject:rootObject toFile:(NSString *)path;
  38.     /* returns whether successful */
  39.  
  40. + (NSString *)classNameEncodedForTrueClassName:(NSString *)trueName;
  41.     /* Returns the name used to archive instances of class trueName */
  42.  
  43. @end
  44.  
  45. /************        Archiving: Reading        ****************/
  46.  
  47. @interface NSUnarchiver:NSCoder {
  48.     @private
  49.     id            data;
  50.     unsigned        cursor;
  51.     NSZone        *objectZone;
  52.     unsigned        systemVersion;
  53.     signed char        streamerVersion;
  54.     void        *pointerTable; // num -> pointer (offset to avoid -1)
  55.     void        *stringTable; // num -> string (offset to avoid -1)
  56.     void        *classVersions;    /* className -> version */
  57.     int            lastLabel;
  58. }
  59.  
  60. - initForReadingWithData:(NSData *)data;
  61.  
  62. - (void)setObjectZone:(NSZone *)zone;
  63.     /* zone may be NULL */
  64.  
  65. - (NSZone *)objectZone;
  66.  
  67. - (BOOL)isAtEnd;
  68.     /* indicates whether or not more data follows. */
  69.  
  70. - (unsigned)systemVersion;
  71.     /* Returns the version used for writing the stream.
  72.     A version less than 1000 means a pre-OpenStep archive */
  73.  
  74. - (void)decodeArrayOfObjCType:(const char *)itemType count:(unsigned)count at:(void *)array;
  75.     /* Expects array to be a previously allocated array of count elements of type itemType. */
  76.     /* objects in array are NOT autoreleased: caller must release */
  77.  
  78. + unarchiveObjectWithData:(NSData *)data;
  79.     /* object is autoreleased */
  80.  
  81. + unarchiveObjectWithFile:(NSString *)path;
  82.     /* Returns nil if file not readable */
  83.     /* object is autoreleased */
  84.  
  85. + (void)decodeClassName:(NSString *)inArchiveName asClassName:(NSString *)trueName;
  86.     /* Enables to change archive names into better names on read;
  87.     Example:
  88.         [NSUnarchiver decodeClassName:@"View" asClassName:@"NSView"]; */
  89.  
  90. + (NSString *)classNameDecodedForArchiveClassName:(NSString *)inArchiveName;
  91.     /* Returns the true classname of objects archived as inArchiveName */
  92.  
  93. @end
  94.  
  95. /************        Object call back        ****************/
  96.  
  97. @interface NSObject (NSArchiver)
  98.  
  99. - (Class)classForArchiver;
  100.     /* Allows substitution of the class used in archiving,
  101.     thus providing very specialized behavior for this style of coding
  102.     and general behavior for others.
  103.     default is to call -classForCoder. */
  104.     
  105. - replacementObjectForArchiver:(NSArchiver *)archiver;
  106.     /* Allows argument to propose a substitute when encoding;
  107.     nil means no to encode nothing;
  108.     default is to call -replacementObjectForCoder: */ 
  109.  
  110. @end
  111.  
  112. /********    Compatibility with NEXTSTEP 3.0 archiving    **********/
  113.  
  114. #import <objc/Object.h>
  115.  
  116. extern void NXWriteNSObject(NXTypedStream *typedStream, NSObject *object);
  117.     /* Writes object onto the typedStream; no sharing is possible across separate NXWriteNSObject */
  118.     
  119. extern NSObject *NXReadNSObject(NXTypedStream *typedStream);
  120.     /* Reads an object written with NXWriteNSObject; returned object is autoreleased */
  121.  
  122. @interface NSCoder (NSTypedstreamCompatibility)
  123.  
  124. - (void)encodeNXObject:(Object *)object;
  125.     /* Writes old-style object onto the coder; no shraing is possible across separate -encodeNXObject */
  126.     
  127. - (Object *)decodeNXObject;
  128.     /* recovers object written with -encodeNXObject */
  129.     
  130. @end
  131.  
  132.